"""Classes to prepare networkx graphs."""

__all__ = ['GraphFactory']

#_______________________________________________________________________________

import logging
import sys

import networkx as nx

from .._debug import logged

#_______________________________________________________________________________

_logger = logging.getLogger('nxchaos.graph')

#_______________________________________________________________________________

class GraphFactory(object):

    def from_nxgraph(self, graph):

        return self.__prepare_graph(graph)

    @logged
    def from_adjlist(self, path):

        graph = nx.read_adjlist(path)

        return self.__prepare_graph(graph)

    @logged
    def from_builtin(self, name, **params):

        _module = __import__(name, globals(), locals(), [], level=-1)
        return self.__prepare_graph(_module.build(**params))

    def __prepare_graph(self, graph):
        
        #graph.workers = [None] * len(graph)
        graph.workers = {}
        for node in graph:
            graph.workers[node] = None

        return graph
